package com.qsw.pagenumberview.test;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;

import com.qsw.pagenumberview.R;
import com.qsw.pagenumberview.view.PageNumberView;

public class PnvTestActivity extends Activity {
    private static final String TAG = "TAG_PnvTestActivity";

    private PageNumberView pnv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pnv_activity_test_pagenumberview);

        pnv = findViewById(R.id.pnv_pnv);
//        pnv.setMaxPage(100);

        pnv.setOnPageChangeListener(new PageNumberView.OnPageChangeListener() {
            @Override
            public void onPageChange(int page) {
                Log.d(TAG, "页码变化： " + page);
            }
        });
    }

    public void addMaxPage(View view) {
        pnv.setMaxPage(pnv.getMaxPage() + 10);
    }

    public void delMaxPage(View view) {
        pnv.setMaxPage(pnv.getMaxPage() - 3);
    }

    public void addTextSize(View view) {
        pnv.setTextSize(pnv.getTextSize() + 1);
    }

    public void delTextSize(View view) {
        pnv.setTextSize(pnv.getTextSize() - 1);
    }

    public void addShowMaxPageCount(View view) {
        pnv.setMaxShowPageBtnCount((byte) (pnv.getMaxShowPageBtnCount() + 1));
    }

    public void delShowMaxPageCount(View view) {
        pnv.setMaxShowPageBtnCount((byte) (pnv.getMaxShowPageBtnCount() - 1));
    }

    boolean bgSelect = true;

    public void changeBg(View view) {
        if (bgSelect) {
            bgSelect = false;
            pnv.setRbBgDrawableId(R.drawable.pnv_bg_rb_select);
        } else {
            bgSelect = true;
            pnv.setRbBgDrawableId(R.drawable.pnv_selector_bg_rb);
        }
    }

    boolean bgText = true;

    public void changeText(View view) {
        if (bgText) {
            bgText = false;
            pnv.setButtonText("up", "down");
        } else {
            bgText = true;
            pnv.setButtonText(getString(R.string.pnv_page_last), getString(R.string.pnv_page_next));
        }
    }

    public void changeEtInputShow(View view) {
        if (pnv.isShowPageInputView()) {
            pnv.setShowPageInputView(false, 0);
        } else {
            pnv.setShowPageInputView(true, 0);
        }
    }

    int etGravity = 0;

    public void changeGravity(View view) {
        switch (etGravity) {
            case 0:
                etGravity = 1;
                pnv.setShowPageInputView(true, Gravity.BOTTOM);
                break;
            case 1:
                etGravity = 2;
                pnv.setShowPageInputView(true, Gravity.LEFT);
                break;
            case 2:
                etGravity = 3;
                pnv.setShowPageInputView(true, Gravity.TOP);
                break;
            case 3:
                etGravity = 0;
                pnv.setShowPageInputView(true, Gravity.RIGHT);
                break;
        }
    }

    public void changePage(View view) {
        pnv.setPage(pnv.getPage() + 2);
    }
}
